home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 301-325 / disk_313 / uucp / uucp1.lzh / src / sendmail / parse.c < prev    next >
C/C++ Source or Header  |  1990-01-10  |  1KB  |  74 lines

  1.  
  2. /*
  3.  *  PARSE.C
  4.  *
  5.  *  (C) Copyright 1989-1990 by Matthew Dillon,  All Rights Reserved.
  6.  */
  7.  
  8. #include <proto/all.h>
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11.  
  12. /*
  13.  *  PARSEADDRESS()
  14.  *
  15.  *  Takes an address containing ! @ % : and converts it to a level 3 ! path.
  16.  *
  17.  *  [path]@mach     ->  mach[!path]
  18.  *  [path]%mach     ->  mach[!path]
  19.  *  patha:pathb     ->  patha!pathb
  20.  *  patha:pathb:pathc    ->  patha!pathb!pathc
  21.  */
  22.  
  23. ParseAddress(str, buf, len)
  24. char *str;
  25. char *buf;
  26. short len;
  27. {
  28.     short i;
  29.     short j;
  30.     char *base = buf;
  31.     char *ParseAddress2();
  32.  
  33.     for (i = j = 0; i < len; ++i) {
  34.     if (str[i] == ':') {
  35.         buf = ParseAddress2(str + j, buf, i - j);
  36.         *buf++ = '!';
  37.         j = i + 1;
  38.     }
  39.     }
  40.     buf = ParseAddress2(str + j, buf, i - j);
  41.     *buf = 0;
  42.     for (i = 0; base[i] && base[i] != '!'; ++i);
  43.     return((int)i);
  44. }
  45.  
  46. /*
  47.  *  deals with !, @, and %
  48.  */
  49.  
  50. char *
  51. ParseAddress2(addr, buf, len)
  52. char *addr;
  53. char *buf;
  54. short len;
  55. {
  56.     short i;
  57.  
  58.     for (i = len - 1; i >= 0; --i) {
  59.     if (addr[i] == '@' || addr[i] == '%') {
  60.         short j = len - i;
  61.         strncpy(buf, addr + i + 1, j - 1);
  62.         buf += j - 1;
  63.         len -= j;
  64.         if (len)
  65.         *buf++ = '!';
  66.     }
  67.     }
  68.     strncpy(buf, addr, len);
  69.     buf += len;
  70.     return(buf);
  71. }
  72.  
  73.  
  74.